package com.api.fc;

import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.docs.docs.util.DesUtils;
import weaver.general.Util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


@Path("/DownloadFj")
public class DownloadFj {

//    private static final String ipport = "http://192.168.0.16:8899";//切换自己的实际地址
//
//    @Path("/down")
//    @POST
//    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED, "text/html; charset=UTF-8"})
//    @Produces({MediaType.APPLICATION_JSON, "text/html; charset=UTF-8"})
//    public Response changeDevice(@Context HttpServletResponse response, @Context HttpServletRequest request) throws Exception {
//        // 设置 CORS 头 为了解决浏览器跨域资源问题
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
//        response.setHeader("Access-Control-Max-Age", "3600");
//        response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me");
//
//        String docid = Util.null2String(request.getParameter("docid"));
//        String[] docids = docid.split(",");
//        List<String> fileUrls = new ArrayList<>();
//        RecordSet rs = new RecordSet();
//        for (String id : docids) {
//            String sql = "select imagefileid from docimagefile where docid=?";
//            rs.executeQuery(sql, id);
//            if (rs.next()) {
//                String imagefileid = rs.getString("imagefileid");
//                String encrypt = new DesUtils().encrypt(1 + "_" + imagefileid);
//                String fileUrl =ipport + "/weaver/weaver.file.FileDownload?fileId=" + imagefileid + "&download=1&ddcode=" + encrypt;
//                fileUrls.add(fileUrl);
//            }
//        }
//
//        if (fileUrls.isEmpty()) {
//            return Response.status(Response.Status.BAD_REQUEST)
//                    .entity("{\"error\":\"找不到文件\"}")
//                    .type(MediaType.APPLICATION_JSON)
//                    .build();
//        }
//
//        String jsonResponse = new Gson().toJson(Collections.singletonMap("redirectUrls", fileUrls));
//        // 返回所有的下载链接
//        return Response.ok(jsonResponse)
//                .type(MediaType.APPLICATION_JSON)
//                .build();
//    }
//
}
